<?php
namespace TwinPeaks\Core;
class CElement
{
	const EL_TYPE_VOID = 1;
	const EL_TYPE_NON_VOID = 2;
	
	const ATTR_SYNTAX_EMPTY = 1;
	const ATTR_SYNTAX_SINGLE_QUOTED = 1;

	/**
	 * @var string Element name
	 */
	private $elName;
	
	/**
	 * 
	 */
	private $elAttrs = [];
	
	private $elType;
	
	private $content;
	
	/**
	 * @return
	 */
	function __construct($name, $type = null)
	{
		$this->elName = $name;
	}
	
	static function setAttValueType()
	{}
	
	/**
	 * @return string
	 */
	static function attrValueEscape($value)
	{
		return $value;
	}
	
	function getContent()
	{
		return $this->content;
	}
	
	/**
	 * @return
	 */
	final function toString()
	{
		$elStr = '<' . $this->elName;
		foreach ($this->elAttrs as $attrName => $attrValue)
		{
			$elStr .= ' ' . $attrName . '=';
			$elStr .= '"' . static::attrValueEscape($attrValue) . '"';
		}
		$elStr .= '>';
		if ($this->elType == self::EL_TYPE_VOID)
			return $elStr;
		
		if (is_array($this->content))
			foreach ($this->content as $nestedEl)
				$elStr .= $nestedEl->toString();
		
		$elStr .= '</' . $this->elName . '>';
		return $elStr;
	}

	/**
	 * 
	 */
	final function __toString()
	{
		$this->toString();
	}
}